package com.atguigu.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.dto.PayDto;
import com.atguigu.cloud.resp.ResultData;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {

    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping(value = "/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDto payDto) {
        System.out.println("第一步: 模拟本地addOrder新增订单成功(省略sql操作)");
        System.out.println("第二步: 开启addPay支付微服务远程调用");
        return payFeignApi.addOrder(payDto);
    }

    @GetMapping(value = "/feign/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id) {
        System.out.println("支付微服务远程调用, 按照id查询订单支付流水信息");
        try {
            System.out.println("feign调用开始时间: " + DateUtil.now());
            payFeignApi.getPayInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(">>>>>>>>Feign调用接口超时<<<<<<<<<");
            System.out.println("feign调用结束时间: " + DateUtil.now());
        }
        return payFeignApi.getPayInfo(id);
    }

    @GetMapping(value = "/feign/pay/mylb")
    public String mylb() {
        System.out.println("openFeign天然支持负载均衡演示");
        return payFeignApi.mylb();
    }

}
